class CompanyApi < Grape::API
  prefix :api
  namespace :company do
    mount BaseApi
    mount ContactApi
    mount FollowupRecordApi

    desc '新增公司'
    params do
      requires :name, type: String
      optional :phone_no, type: String
      optional :postal_code, type: String 
      optional :address, type: String
      optional :followup_employee_code, type: String
    end
    post 'add_company' do
      content_type 'application/json'
      CompanyService.add(params)
    end

    # 入参：page 页码，per_page 每页显示数量
    desc '公司列表分页查询'
    params do
      requires :page, type: Integer, default: 1
      requires :per_page, type: Integer, default: 10
    end
    get '/page_query' do
      Rails.logger.info('company_api#page_query') { 'page_query started.....' }
      CompanyService.page_query(params[:page], params[:per_page])
    end

    # 入参：公司id
    desc '根据公司id查询公司记录'
    params do
      requires :id, type: Integer
    end
    get '/query_by_id' do
      CompanyService.query_by_id(params[:id])
    end

    desc '更新公司信息'
    params do
      requires :name, type: String
      optional :phone_no, type: String
      optional :postal_code, type: String 
      optional :address, type: String
      optional :followup_employee_code, type: String
    end
    post 'update' do
      content_type 'application/json'
      CompanyService.update(params)
    end

    desc '删除公司记录'
    params do
      requires :id, type: Integer
    end
    post 'delete' do
      content_type 'application/json'
      CompanyService.delete_by_id(params[:id])
    end

  end
end
